package com.herench.bunch.peis.handler;


import com.herench.bunch.commons.annotation.Handler;
import com.herench.bunch.commons.support.AbstractMessageHandler;
import com.herench.bunch.commons.support.WsClientFactory;
import com.herench.bunch.peis.convert.PeisApplicationConvert;
import org.apache.cxf.endpoint.Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import java.util.Map;


/**
 * @author luoxiaoming on 18-9-17 下午5:11
 * @email luoxiaoming@herench.com
 */
@PropertySource("classpath:environment.properties")
@Handler(code = "10830" ,name = " PACS获取申请单信息" ,messageConvertClass = PeisApplicationConvert.class)
public class PeisApplicationHandler extends AbstractMessageHandler {

    @Autowired
    private Environment environment;
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    protected Object proxyInvoke(Object inMessage) throws Exception {
        Map<String,Object> resMap = (Map<String, Object>) inMessage;
        String url = environment.getProperty("peis.url");
        logger.info("url = "+ url);
        Client client = WsClientFactory.getInstance().getWsClient(url);
        Object[] res = client.invoke("send", resMap.get("msg"));
        return  res[0];
    }
}